<?php
require_once './core/tools.php';



if (isset($_POST["login"]) && isset($_POST["password"])){
	
	$query = "SELECT * FROM  `versions_user` WHERE  `login` =  '" .$_POST["login"] . "' AND  `password` = SHA1(  '" . $_POST["password"] . "' ) ";
	$result = executeSQL($query);
	
	if (!$result){
		die ('{"error":1, "message":"MysqlError :'.addslashes(mysql_error()).'"}' );
	}
	
	$num_rows = mysql_num_rows($result);
	
	if ($num_rows >= 1){
		session_start();
		$_SESSION['logged'] = true ;
		
		
		echo '{"error":0, "message":"OK"}';
	}
	else {
		echo '{"error":3, "message":"Unknown user"}';	
	}
	
}
else {
	echo '{"error":2, "message":"missing parameters"}';
}
?>